package com.demo2do.fms.entity.appraisal;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;

/**
 * 绩效考核模板 - 单项考核模板
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "FMS_APPRAISAL_TEMPLATE_ITEM")
@PersistentFormat
public class AppraisalTemplateItem {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 所属考核标准 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private AppraisalTemplate parent;
    
    /** 名称 */
    private String name;
    
    /** 分数上限 */
    private BigDecimal score;
    
    /** 考核部门 */
    private String auditor;
    
    /** 创建人 */
    private Long creator;

    /** 创建时间 */
    private Date createTime;

    /** 最后修改人 */
    private Long lastOperator;

    /** 最近修改时间 */
    private Date lastModifyTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public AppraisalTemplateItem() {
    }

    /**
     * @param parent
     * @param operator
     * @return
     */
    public AppraisalTemplateItem initialize(AppraisalTemplate parent, Long operator) {
        this.parent = parent;
        this.disabled = false;
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param item
     * @param operator
     * @return
     */
    public AppraisalTemplateItem edit(AppraisalTemplateItem item, Long operator) {
        this.name = item.getName();
        this.score = item.getScore();
        this.auditor = item.getAuditor();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public AppraisalTemplateItem delete(Long operator) {
        this.disabled = true;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the parent
     */
    public AppraisalTemplate getParent() {
        return parent;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the score
     */
    public BigDecimal getScore() {
        return score;
    }

    /**
     * @return the auditor
     */
    public String getAuditor() {
        return auditor;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param parent the parent to set
     */
    public void setParent(AppraisalTemplate parent) {
        this.parent = parent;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param score the score to set
     */
    public void setScore(BigDecimal score) {
        this.score = score;
    }

    /**
     * @param auditor the auditor to set
     */
    public void setAuditor(String auditor) {
        this.auditor = auditor;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}